// pages/welcome/welcome.js
const util = require("../../utils/util.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    skipText: '跳过5'
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    util.setBarColor()
    this.skipTimer();
    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  skipTimer: function () {
    var that = this
    var timer = setInterval(function () {
      var skipText = that.data.skipText;
      var second = parseInt(skipText.replace('跳过', ''));
      if (second === 1) {
        clearInterval(timer); //显示当前时间 ( setInterval() 函数会每秒执行一次函数，类似手表)。使用 clearInterval() 来停止执行:
        that.skipWelcome();
      } else {
        that.setData({
          skipText: '跳过' + (second - 1)
        })
      }
    }, 1000)
  },

  skipWelcome: function () {
    var user = wx.getStorageSync("userInfo");
    if (user != null && user != "") {
      wx.switchTab({
        url: '/pages/index/index',
      })
    }else{
      wx.navigateTo({
        url: '/pages/login/login',
      })
    }
  }

})